package main

import (
	"gc-rds-ha/internal/common/server"
	"os"
	"os/signal"
	"syscall"

	log "github.com/sirupsen/logrus"
)

func main() {
	defer func() {
		if r := recover(); r != nil {
			log.Infof("[main] %s recover painc:%s.", server.GcRdsHa, r)
			os.Exit(-1)
		}
	}()

	// wait signal and exit
	go func() {
		signals := make(chan os.Signal, 1)
		signal.Notify(signals,
			syscall.SIGTERM,
			syscall.SIGINT,
			//syscall.SIGKILL,
			syscall.SIGHUP,
			syscall.SIGQUIT,
		)
		<-signals
		exit(0)
	}()
	server.Run()
}

func exit(status int) {
	server.Stop()
	log.Infof("[main] %s exit:%d.", server.GcRdsHa, status)
	os.Exit(status)
}
